from gen_py.hello import *
from gen_py.hello.Hello import Processor
from gen_py.hello.ttypes import *
import sys
from thrift.Thrift import TType,TMessageType,TException,TProcessor
from thrift.transport import TSocket
from thrift.protocol import TBinaryProtocol,TProtocol
from thrift.server import TServer
import logging
from gen_py.hello.constants import *
import zlib
import base64

logging.basicConfig(filename="logger.log",level=logging.INFO,format='%(asctime)s %(filename)s : %(levelname)s %(message)s',datefmt='%Y-%m-%d %H:%M:%S',filemode="w+")
# format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
class helloHandle:

    def say(self,name):
       logging.info(msg='recev data')
       #print("recive data:"+str(name))
       # names = str(name).decode("utf-8")
       # print(names)
       cstr = base64.decode(name)
       print(cstr)
       # com_str = zlib.decompress(cstr,-15)
       # print(com_str)
       return "Python Return"



def run():

    handler = helloHandle()
    processor = Processor(handler)

    transport = TSocket.TServerSocket("localhost",9090)
    tfactory = TTransport.TBufferedTransportFactory()
    pfactory = TBinaryProtocol.TBinaryProtocolFactory()
    server = TServer.TThreadPoolServer(processor,transport,tfactory,pfactory)
    server.setNumThreads(5)
    logging.info(msg='server start')
    server.serve()
    logging.info(msg='server done')


if __name__ == '__main__':

    run()








